class ListNode:
    def __init__(self, val: int):
        self.val = val
        self.next: ListNode | None = None

    def list_to_linked_list(arr: list[int]):
        dum = head = ListNode(0)
        for a in arr:
            node = ListNode(a)
            head.next = node
            head = head.next
        return dum

    def linked_list_to_list(head):
        arr = []
        while head:
            arr.append(head.val)
            head = head.next
        return arr

if __name__ == "__main__":
    arr = [1, 2, 3, 4, 5]
    head = ListNode.list_to_linked_list(arr)
    # while head:
    #     print(head.val)
    #     head = head.next
    print(ListNode.linked_list_to_list(head))
